package boxoffice;

import java.awt.*;
import javax.swing.*;
import boxoffice.Event;
import java.text.SimpleDateFormat;
import boxoffice.ImageScrollFrame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * TicketWindow - The window that appears to display a couple more facts about
 * the event you want to purchase tickets for.
 * @author Alex
 */
public class TicketWindow extends JFrame implements ActionListener {

    public static final Dimension FRAMESIZE = new Dimension(600, 300);
    
    private JTextArea text;
    private JButton purchaseTickets;
    private SimpleDateFormat simpdate = new SimpleDateFormat("yyyy/mm/dd");
    // Picture Boxes
    private ImageScrollFrame picture;
    private PurchaseWindow purcWin;
    private JButton showPicture;
    
    private Event data;
    
    /**
     * TicketWindow - Yay constructors! This just puts our window together.
     */
    public TicketWindow() {
        text = new JTextArea();
        purcWin = new PurchaseWindow();
        purcWin.setVisible(false);
        
        purchaseTickets = new JButton("Purchase Tickets");
        showPicture = new JButton("Display Floor Plan");
        
        purchaseTickets.addActionListener(this);
        showPicture.addActionListener(this);
        
        picture = new ImageScrollFrame("C:/Users/Alex/Documents/"
                + "NetBeansProjects/JavaSwingApp/RoyalMain.png");
        picture.setVisible(false);
        
        JPanel contain = new JPanel(new GridLayout(2,0));
        
        Container content = this.getContentPane();
        
        contain.add(text, BorderLayout.NORTH);
        contain.add(purchaseTickets, BorderLayout.SOUTH);
        contain.add(showPicture, BorderLayout.EAST);
        
        content.add(contain, BorderLayout.CENTER);
        
        this.setSize(FRAMESIZE);
        this.setPreferredSize(FRAMESIZE);
    }
    
    /**
     * sendData - This sends data to our actual window for displaying to the
     * user. Really it should be called 'grabData'.
     * @param ev The Event object being given to us by the JavaSwingApp.
     */
    public void sendData(Event ev) {
        data = ev;
        float[] prices = data.getPrices();
        
        text.setText("This is the event you've selected. \nEvent: " + 
                data.getType() + "\nName: " + data.getName() + "\nDate: " + 
                simpdate.format(data.getDate().getTime()) + "\nTicket Price: "
                + "\nBox Seat: $" + prices[0] + "\nFront Row: $" + prices[1]);
    }
    
    /**
     * actionPerformed - The function that triggers whenever a user does
     * something with our buttons on the window.
     * 
     * @param e The ActionEvent being caught by the function.
     */
    public void actionPerformed(ActionEvent e) {
        if (e.getSource() == showPicture) {
            picture.setVisible(true);
        }
        
        if (e.getSource() == purchaseTickets) {
            purcWin.setVisible(true);
        }
    }
}
